//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Eas.WebCrawler.Test.PlugIns {
    /// <summary>
    /// Summary description for TestUrlEnumerator
    /// </summary>
    [TestClass]
    public class TestUrlEnumerator {
        public TestUrlEnumerator() {
            //
            // TODO: Add constructor logic here
            //
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        [TestInitialize()]
        public void MyTestInitialize() { TestDirectoryHelper.Setup(); }
        //
        // Use TestCleanup to run code after each test has run
        [TestCleanup()]
        public void MyTestCleanup() { TestDirectoryHelper.TearDown(); }
        //
        #endregion

        [TestMethod]
        /// <summary>Executes the TestMain test.</summary>
        public void TestMain() {
            string file1 = TestDirectoryHelper.Name(TestDirectory.Source, "Uris.txt");
            string file2 = TestDirectoryHelper.Name(TestDirectory.Source, "Uris2.txt");
            IEnumerable<string> uris = Eas.WebCrawler.PlugIns.UrlEnumerators.FileBasedUrlEnumerator.GetStartingUris(file1, file2);
            IEnumerator<string> enumerator = uris.GetEnumerator();
            CheckUri("http://www.yahoo.com", enumerator);
            CheckUri("http://www.msn.com", enumerator);
            CheckUri("http://www.microsoft.com", enumerator);
            CheckUri("http://www.saltwell.com", enumerator);
            CheckUri("http://www.erik.com/temp.aspx", enumerator);
            Assert.IsFalse(enumerator.MoveNext());

        }

        private void CheckUri(string uri, IEnumerator<string> enumerator) {
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual<string>(uri, enumerator.Current);
        }
    }
}
